package mao.redis.jedisdelayqueue;
import java.util.concurrent.TimeUnit;

/**
 * @author Totoro
 * @date 2020/5/28
 * @explain:
 */
public class Consumer implements Runnable {
    public RedisDelayQueue queue;

    public Consumer(RedisDelayQueue queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (!Thread.interrupted()) {
            String msg = queue.get();
            //System.out.println(Thread.currentThread().getName());
            if (msg != null) {
                System.out.println(Thread.currentThread().getName()+" consumer: "+ msg);
            }else {
                try{
                    TimeUnit.MILLISECONDS.sleep(10);
                }catch (InterruptedException e){
                    break;
                }
            }
        }
    }
}
